package com.wanmait.travel.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.travel.dao.ScenicDAO;
import com.wanmait.travel.dao.TickitDAO;
import com.wanmait.travel.vo.Scenic;
import com.wanmait.travel.vo.ScenicTickitType;
import com.wanmait.travel.vo.Tickit;

@WebServlet("/ShowServlet")
public class ShowServlet extends HttpServlet {
	
	private TickitDAO tickitDAO= TickitDAO.getDAO();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String action= request.getParameter("action");
		if (action == null) {
			response.sendRedirect("/Travel/scenic/main.jsp");
			return;
		}
		switch(action){
		case "list":
			this.list(request, response);
			break;
	}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}
	protected void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String path=request.getServletContext().getContextPath();
		String idstr=request.getParameter("id");
		int id=Integer.parseInt(idstr);
		Scenic scenic=tickitDAO.findAll(id);
		ScenicTickitType stt=tickitDAO.findByTickit(scenic);
		request.setAttribute("stt", stt);
		request.getRequestDispatcher("/scenic/scenicshow.jsp").forward(request, response);
	}
	
}
